<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;

class SyncBankDetailsJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public string $account;
    public string $bank;
    public int $days;

    /**
     * Create a new job instance.
     */
    public function __construct(string $account, string $bank = 'BankOfHangzhou', int $days = 1)
    {
        $this->account = $account;
        $this->bank = $bank;
        $this->days = $days;
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        Log::info('Dispatching bank details sync job', [
            'account' => $this->account,
            'bank' => $this->bank,
            'days' => $this->days,
        ]);

        Artisan::call('bank:sync-details', [
            '--account' => $this->account,
            '--bank' => $this->bank,
            '--days' => $this->days,
        ]);
    }
}
